package com.lanou.controller;

import com.lanou.entity.ChargingStandards;
import com.lanou.service.ChargingStandardsService;
import com.lanou.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName ChargingStandardsController
 * @Description TODO
 * @Author chenzhaobao
 * @Date 2025年08月14日 10:56
 * @Version 1.0
 */
@RestController
@RequestMapping("/chargingStandards")
public class ChargingStandardsController {
    @Autowired
    private ChargingStandardsService chargingStandardsService;
    @PostMapping
    public R insertChargingStandards(@RequestBody ChargingStandards chargingStandards) {
        int i = chargingStandardsService.insert(chargingStandards);
        if (i > 0) {
            return R.ok("新增成功");
        } else {
            return R.fail("新增失败");
        }
    }
    @DeleteMapping("/{id}")
    public R deleteChargingStandards(@PathVariable  Integer id) {
        int i = chargingStandardsService.deleteById(id);
        if (i > 0) {
            return R.ok("删除成功");
        }else {
            return R.fail("删除失败");
        }
    }
    @PutMapping
    public R updateChargingStandards(@RequestBody ChargingStandards chargingStandards) {
        int i = chargingStandardsService.updateById(chargingStandards);
        if (i > 0) {
            return R.ok("修改成功");
        }else{
            return R.fail("修改失败");
        }
    }
    @GetMapping("/{id}")
    public R getChargingStandards(@PathVariable  Integer id) {
        ChargingStandards chargingStandards = chargingStandardsService.selectById(id);
        if (chargingStandards != null) {
            return R.ok(chargingStandards);
        }else {
            return R.fail("查询失败");
        }
    }
    @GetMapping
    public R getAllChargingStandards() {
        List<ChargingStandards> chargingStandardsList = chargingStandardsService.selectAll();
        if (chargingStandardsList != null && chargingStandardsList.size() > 0) {
            return R.ok(chargingStandardsList);
        }else {
            return R.fail("查询失败");
        }
    }
    @GetMapping("/consultant/{consultantId}")
    public R getChargingStandardsByConsultantId(@PathVariable  Integer consultantId) {
        List<ChargingStandards> chargingStandardsList = chargingStandardsService.selectByConsultantId(consultantId);
        if (chargingStandardsList != null && chargingStandardsList.size() > 0) {
            return R.ok(chargingStandardsList);
        }else {
            return R.fail("查询失败");
        }
    }
}
